package cn.ckx.coding.common.dto;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;
import lombok.Data;

import java.util.Optional;

@ApiModel(description = "分页")
@Data
public class Pageable {
    
    private static final int DEFAULT_PAGE = 1;

    private static final int DEFAULT_PAGE_SIZE = 10;

    @ApiParam(value = "页码", example = "1")
    protected Integer page;

    @ApiParam(value = "页面大小", example = "10")
    protected Integer pageSize;

    public <T> IPage<T> toPage() {
        Page<T> pager = new Page<>();
        pager.setCurrent(Optional.ofNullable(page).orElse(DEFAULT_PAGE));
        pager.setSize(Optional.ofNullable(pageSize).orElse(DEFAULT_PAGE_SIZE));
        return pager;
    }

}
